﻿Imports System.IO
Imports GalgameParser
Imports System.IO.IsolatedStorage
Imports ICSharpCode.SharpZipLib.Zip
Imports System.Runtime.CompilerServices

Module Extension

    <Extension()> _
    Public Sub DeleteDirectory(ByVal [Me] As IsolatedStorageFile, ByVal dirName As String, ByVal recursive As Boolean)
        If recursive Then
            Dim stk As New Stack(Of String)
            stk.Push(dirName)
            While stk.Count > 0
                Dim currentPath As String = stk.Pop()
                Dim currentFiles = [Me].GetFileNames(IO.Path.Combine(currentPath, "*.*"))
                Dim currentDirs = [Me].GetDirectoryNames(IO.Path.Combine(currentPath, "*."))
                For Each fi In currentFiles
                    [Me].DeleteFile(IO.Path.Combine(currentPath, fi))
                Next
                If currentDirs.Length = 0 Then
                    [Me].DeleteDirectory(currentPath)
                End If
                For Each dir In currentDirs
                    stk.Push(IO.Path.Combine(currentPath, dir))
                Next
            End While
        Else
            [Me].DeleteDirectory(dirName)
        End If
    End Sub

End Module